import SwiftUI

struct NowViewTabs: View {
    @Binding var selectedTab: String
    @Binding var fav_type: Int
    @State private var hasAppeared = false
    
    var body: some View {
        HStack {
            Button {
                self.selectedTab = "tv"
                self.fav_type = 1
                triggerHapticFeedback()  // 直接调用扩展中的方法
            } label: {
                Image(systemName: "tv")
                if selectedTab == "tv" {
                    Text("收藏夹")
                }
            }
            .padding()
            .frame(maxWidth: selectedTab == "tv" ? .infinity : 60)
            .background(selectedTab == "tv" ? .blue.opacity(0.8) : .white.opacity(0.3))
            .clipShape(RoundedRectangle(cornerRadius: 20.0))
            
            
            Button {
                self.selectedTab = "hourglass"
                self.fav_type = 3
                triggerHapticFeedback()  // 直接调用扩展中的方法
            } label: {
                Image(systemName: "hourglass")
                if selectedTab == "hourglass" {
                    Text("稍后观看")
                }
            }
            .padding()
            .frame(maxWidth: self.selectedTab == "hourglass" ? .infinity : 60)
            .background(self.selectedTab == "hourglass" ? .orange.opacity(0.2) : .white.opacity(0.3))
            .clipShape(RoundedRectangle(cornerRadius: 20.0))
            
            Button {
                self.selectedTab = "clock"
                self.fav_type = 2
                triggerHapticFeedback()  // 直接调用扩展中的方法
            } label: {
                Image(systemName: "clock")
                if selectedTab == "clock" {
                    Text("观看记录")
                }
            }
            .padding()
            .frame(maxWidth: selectedTab == "clock" ? .infinity : 60)
            .background(selectedTab == "clock" ? Color("MainColor"): .white.opacity(0.3))
            .clipShape(RoundedRectangle(cornerRadius: 20.0))
      
            
            NavigationLink {
                SearchView()
            } label: {
                Image(systemName: "magnifyingglass")
            }
            .padding()
        }
        .animation(.default, value: selectedTab)
        .font(.system(size: 20, weight: .black))
        .foregroundStyle(.white)
        .padding(10)
        .padding(.top, 50)

    }
    
}



struct NowViewabser_Previews: PreviewProvider {
    @State static var selectedTab: String = "tv"
    @State static var fav_type: Int = 2

    static var previews: some View {
        NowViewTabs(selectedTab: $selectedTab, fav_type: $fav_type)
            .background(Color("BgColor1"))
    }
}
